import { cloudService } from './index'
import { ITravelQuery, ITravelRecord, ITravelSpot, ITravelStats } from '@/types/travel'

export const addTravelSpotApi = (travelSpot: ITravelSpot): Promise<boolean> =>
  cloudService({
    url: '/home-api/travel/spot',
    method: 'post',
    data: travelSpot
  })

export const updateTravelSpotApi = (id: number, travelSpot: ITravelSpot): Promise<boolean> =>
  cloudService({
    url: `/home-api/travel/spot/${id}`,
    method: 'put',
    data: travelSpot
  })

export const deleteTravelSpotApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/travel/spot/${id}`,
    method: 'DELETE'
  })

export const queryTravelSpotApi = (id: number): Promise<ITravelSpot> =>
  cloudService({
    url: `/home-api/travel/spot/${id}`,
    method: 'get'
  })

export const queryTravelSpotListApi = (currentPage: number, pageSize: number,
  query: ITravelQuery): Promise<any> =>
  cloudService({
    url: '/home-api/travel/spot/page',
    method: 'get',
    params: { currentPage, pageSize, ...query }
  })

export const queryTravelSpotNameListApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/travel/spot/name',
    method: 'get'
  })

export const addTravelRecordApi = (travelRecord: ITravelRecord): Promise<boolean> =>
  cloudService({
    url: '/home-api/travel/record',
    method: 'post',
    data: travelRecord
  })

export const updateTravelRecordApi = (id: number, travelRecord: ITravelRecord): Promise<boolean> =>
  cloudService({
    url: `/home-api/travel/record/${id}`,
    method: 'put',
    data: travelRecord
  })

export const deleteTravelRecordApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/travel/record/${id}`,
    method: 'DELETE'
  })

export const queryTravelRecordApi = (startDate: string, endDate: string):
Promise<ITravelRecord[]> =>
  cloudService({
    url: '/home-api/travel/record',
    method: 'get',
    params: { startDate, endDate }
  })

export const queryTravelCategoryApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/travel/category',
    method: 'get'
  })

export const queryTravelStatsApi = (): Promise<ITravelStats> =>
  cloudService({
    url: '/home-api/travel/stats',
    method: 'get'
  })
